package com.nd.service.wx;

import cn.hutool.core.date.DateTime;
import com.nd.dao.FeedbackMapper;
import com.nd.pojo.bean.Admin;
import com.nd.pojo.bean.Feedback;
import com.nd.pojo.bean.User;
import com.nd.pojo.bo.wx.FeebackBo;
import com.nd.pojo.vo.wx.BaseRespWXVo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @program: project2mall
 * @description: 反馈Service
 * @author: shit_code_builder
 * @create: 2021-06-07 22:24
 **/
@Service
public class FeebackService
{
    @Autowired
    FeedbackMapper feedbackMapper;

    public BaseRespWXVo submitFeedback(FeebackBo bo) {
        Subject subject = SecurityUtils.getSubject();
        User user = (User) subject.getPrincipal();
        Date lastLoginTime = user.getLastLoginTime();
        Feedback build = Feedback.builder().
                mobile(bo.getMobile()).
                feedType(bo.getFeedType()).
                addTime(lastLoginTime).
                content(bo.getContent()).
                deleted(false)
                .hasPicture(bo.isHasPicture())
                .picUrls( bo.getPicUrls().toArray(new String[bo.getPicUrls().size()]))
                .status(200)
                .updateTime(DateTime.now())
                .userId(user.getId())
                .username(user.getUsername()).build();

        feedbackMapper.insert(build);

        BaseRespWXVo baseRespWXVo = new BaseRespWXVo();
        return baseRespWXVo.ok();

    }
}
